From ba9a170df2b785c1e5a3e277caba71ef89216d07 Mon Sep 17 00:00:00 2001 From: jeroendedauw Date: Thu, 29 Nov 2012 18:03:03 +0100 Subject: [PATCH] Added assertException method to MediaWikiTestCase Change-Id: I3ce667b4405241c66c5a979863d1cea2cf39956b --- tests/phpunit/MediaWikiTestCase.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index b6a4a944ee..a594202106 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -830,4 +830,32 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $this->markTestSkipped( "Skip test, since diff3 is not configured" ); } } + + /** + * Asserts that an exception of the specified type occurs when running + * the provided code. + * + * @since 1.21 + * + * @param callable $code + * @param string $expected + * @param string $message + */ + protected function assertException( $code, $expected = 'Exception', $message = '' ) { + $pokemons = null; + + try { + call_user_func( $code ); + } + catch ( Exception $pokemons ) { + // Gotta Catch 'Em All! + } + + if ( $message === '' ) { + $message = 'An exception of type "' . $expected . '" should have been thrown'; + } + + $this->assertInstanceOf( $expected, $pokemons, $message ); + } + } -- 2.20.1